<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>学员登陆</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/component/layui/css/layui.css}"/>
  <link rel="stylesheet" th:href="@{/assets/style.css}"/>
  <link rel="stylesheet" th:href="@{/assets/global.css}"/>
</head>
<body>
<!-- 顶部 -->
<th:block th:include="edu/front/common/header :: header"/>
<div class="layui-container fly-marginTop">
  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title">
        <li class="layui-this">登入</li>
      </ul>
      <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
        <div class="layui-tab-item layui-show">
          <div class="layui-form layui-form-pane">
            <form method="post" action="/default/tologin">
              <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                  <input type="text" name="username" required lay-verify="required" value="zhangsan" autocomplete="off"
                         class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                  <input type="password" name="password" required lay-verify="required" value="123456"
                         autocomplete="off"
                         class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">验证码</label>
	            <div class="layui-input-inline">
                  <input class="layui-input" name="code" placeholder="请输入验证码" autocomplete="off" lay-verify="" required/>
                </div>
                <img class="login-captcha" th:src="@{/front/captcha}" alt="captcha" id="captchaImage"/>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn login" lay-submit lay-filter="login">立即登录</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 底部 -->
<th:block th:include="edu/front/common/footer :: footer"/>
<th:block th:include="edu/front/common/js :: js"/>
<script type="text/javascript">
  layui.use(['form','jquery','layer'], function() {
    let form = layui.form;
    let $ = layui.jquery;
    let layer = layui.layer;
    let captchaPath = "/front/captcha";
    $("#captchaImage").click(function(){
      document.getElementById("captchaImage").src= captchaPath + "?" + Math.random();
    })
    form.on('submit(login)', function(data){
      let loader = layer.load();
      $.ajax({
        url:'/login',
        data:data.field,
        type:"post",
        dataType:'json',
        success:function(result){
          layer.close(loader);
          if(result.success){
            location.href = "/front/index";
          }else{
            document.getElementById("captchaImage").src=captchaPath + "?" + Math.random();
          }
        }
      });
      return false;
    });
  });
</script>
</body>
</html>